package com.baichang.taoshunda.dao.impl;

import com.baichang.framework.dao.impl.BaseDaoImpl;
import com.baichang.taoshunda.dao.CompanyPanymentHistoryDao;
import com.baichang.taoshunda.entity.CompanyPanymentHistory;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Map;

/**
 * Created by Administrator on 2018/1/26 0026.
 */
@Repository
public class CompanyPanymentHistoryDaoImpl extends BaseDaoImpl<CompanyPanymentHistory> implements CompanyPanymentHistoryDao {

    /***
     * 查询最新创建的数据id
     * @return
     */
    @Override
    public Map<String, Object> queryHistoryId() {
        String sql = "SELECT * FROM {TABLE} ORDER BY created_time DESC LIMIT 1";
        return queryForMap(sql);
    }

    /**
     * 查询广告位申请的时间
     *
     * @param historyId
     * @return
     */
    @Override
    public Map<String, Object> getHistoryInfo(Integer historyId) {
        String sql = "SELECT * FROM {table} WHERE carousel_id=?";
        return queryForMap(sql, historyId);
    }

    /**
     * @param id
     * @param money
     * @param payType
     * @return
     */
    @Override
    public int updateMoney(Integer id, BigDecimal money, Integer payType) {
        String sql = "UPDATE {table} SET payment_money=?,pay_type=? WHERE waiter_service_id=?";
        return update(sql, money, payType, id);
    }

    /**
     * 查询是否有缴费数据
     *
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> getCountWaiter(Integer id) {
        String sql = "SELECT COUNT(*) AS num,waiter_service_id AS waiterId FROM {table} WHERE waiter_service_id=?";
        return queryForMap(sql, id);
    }

    /**
     * 查询推荐商家的缴费信息
     *
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> getRecommend(Integer id) {
        String sql = "SELECT * FROM t_company_panyment_history WHERE recommend_id=?";
        return queryForMap(sql, id);
    }

    /**
     * 查询是否缴纳保障金
     *
     * @param id
     * @return
     */
    @Override
    public int getCountRecord(Integer id) {
        String sql = "SELECT COUNT(0) FROM `t_business_money_record` WHERE `buiness_ud` =?  AND `status` = '1' and type=2";
        return queryForInt(sql, id);
    }

    /**
     * @param waiterId
     * @return
     */
    @Override
    public Map<String, Object> queryUserWaiter(int waiterId) {
        String sql = "SELECT COUNT(*) AS num FROM t_company_panyment_history WHERE waiter_service_id=?";
        return queryForMap(sql, waiterId);
    }

    /**
     * @param id
     * @return
     */
    @Override
    public int deleteCode(Integer id) {
        String sql = " carousel_id=?";
        return delete(sql, id);
    }

    @Override
    public CompanyPanymentHistory gethistoryByGoodsId(Integer goodsId) {

        String sql = " SELECT * FROM t_company_panyment_history WHERE good_id =? ORDER BY id DESC LIMIT 1 ";
        return queryForBean(sql, goodsId);
    }
}
